package com.jt.dify.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class R implements Serializable {

    // 序列化版本号
    private static final long serialVersionUID = 1L;

    // 预定的状态码
    public static final int CODE_200 = 200;
    public static final int CODE_401 = 401;
    public static final int CODE_500 = 500;

    private int code;
    private String msg;
    private Object data;

    public R(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // ============================  静态方法快速构建  ==================================

    // 构建成功
    public static R ok() {
        return new R(CODE_200, "ok", null);
    }

    public static R ok(String msg) {
        return new R(CODE_200, msg, null);
    }

    public static R code(int code) {
        return new R(code, null, null);
    }

    public static R data(Object data) {
        return new R(CODE_200, "ok", data);
    }

    public static R data(Object data,String msg) {
        return new R(CODE_200, msg, data);
    }

    // 构建失败
    public static R error() {
        return new R(CODE_500, "error", null);
    }

    public static R error(String msg) {
        return new R(CODE_500, msg, null);
    }

    public static R error(int code, String msg) {
        return new R(code, msg, null);
    }

    // 构建指定状态码
    public static R result(int code, String msg, Object data) {
        return new R(code, msg, data);
    }


}
